using Unity.Burst;
using Unity.Entities;

partial struct DestroySystem : ISystem
{
    [BurstCompile]
    public void OnCreate(ref SystemState state)
    {
        
    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        var system = SystemAPI.GetSingleton<BeginSimulationEntityCommandBufferSystem.Singleton>();
        var ecb = system.CreateCommandBuffer(state.WorldUnmanaged).AsParallelWriter();
        new ProcessDestroyJob
        {
            Ecb = ecb,
        }.Run();
    }

    [BurstCompile]
    public partial struct ProcessDestroyJob : IJobEntity
    {
        public EntityCommandBuffer.ParallelWriter Ecb;
        private void Execute([ChunkIndexInQuery] int chunkIndex, DestroyComponent spawner, Entity entity)
        {
            Ecb.DestroyEntity(chunkIndex, entity);
        }
    }

    [BurstCompile]
    public void OnDestroy(ref SystemState state)
    {
        
    }
}